﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CommandLine;
using CommandLine.Text;

namespace SPProfileData
{
    class Options
    {
        private static readonly HeadingInfo headingInfo = new HeadingInfo("SharePoint Profile Data Import Export", "1.0");

        [Option("u", "url", Required = true, HelpText = "The SharePoint site collection URL")]
        public string Url = String.Empty;

        [Option("i", "import", MutuallyExclusiveSet = "ie", HelpText="Run the importer")]
        public bool Import = false;

        [Option("e", "export", MutuallyExclusiveSet = "ie", HelpText="Run the exporter")]
        public bool Export = false;

        [Option("f", "file", Required = true, HelpText = "The file to read the import from, or write the export to")]
        public string FileName = String.Empty;

        [HelpOption("?", "help", HelpText="Print this message")]
        public string GetUsage()
        {
            var help = GetHeader();
            help.AddPreOptionsLine("");
            help.AddPreOptionsLine("This is free software. You may redistribute copies of it under the terms of");
            help.AddPreOptionsLine("the MIT License <http://www.opensource.org/licenses/mit-license.php>.");
            help.AddPreOptionsLine("");
            help.AddPreOptionsLine("Usage: profiledump [--import|--export] --file<FILENAME> --url<SITE URL>");
            help.AddPreOptionsLine("       profiledump -e -f dump.xml --url http://example.sharepoint.com");
            help.AddPreOptionsLine("       profiledump -i -f dump.xml --url http://example2.sharepoint.com");
            help.AddOptions(this);

            return help;
        }

        public HelpText GetHeader()
        {
            var header = new HelpText(Options.headingInfo);
            header.Copyright = new CopyrightInfo("Geoff Ford", 2010);
            return header;
        }

        public bool Parse(string[] args)
        {
            ICommandLineParser parser = new CommandLineParser();
            if (!parser.ParseArguments(args, this))
            {
                return false;
            }
            return true;
        }

    }
}
